<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="12">
            <a-form-model-item label="发票号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invoiceNo">
              <a-input :disabled="formDisabled" v-model="model.invoiceNo" placeholder="请输入发票号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="开票日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
              <j-date :disabled="formDisabled" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开票日期" v-model="model.createTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="发票类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invoiceCategory">
              <j-dict-select-tag :disabled="formDisabled" type="list" v-model="model.invoiceCategory" dictCode="invoice_type" placeholder="请选择发票类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="税率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taxRate">
              <j-dict-select-tag :disabled="formDisabled" type="list" v-model="model.taxRate" dictCode="contract_rate_type" placeholder="请选择税率" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="开票金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invoiceAmount">
              <a-input type="number" style="width: 100%" :disabled="formDisabled" :max="99999999" :precision="2" v-model="model.invoiceAmount" placeholder="请输入开票金额(元)" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea :disabled="formDisabled" :max-length="500" v-model="model.remark" rows="4" placeholder="请输入备注"></a-textarea>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发票附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="attachments">
              <j-upload :disabled="formDisabled" v-model="model.attachments"></j-upload>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  export default {
    name: 'ErpFinanceInvoiceHandleRecordForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        flag: false,
        model:{
          invoiceCategory: '0',
          isFree: '1'
        },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 },
        },
        confirmLoading: false,
        validatorRules: {
          createTime: [
              { required: true, message: '请选择开票日期!', trigger: 'change'},
          ],
          invoiceNo: [
              { required: true, message: '请输入发票号码!', trigger: 'blur'},
          ],
          invoiceCategory: [
              { required: true, message: '请选择发票类型!', trigger: 'blur'},
          ],
          attachments: [
              { required: true, message: '请上传发票附件!', trigger: 'blur'},
          ],
          taxRate: [
            { required: true, message: '请选择税率!'},
          ],
          invoiceAmount: [
            { required: true, message: '请输入开票金额!'},
          ],
          // isFree: [
          //     { required: true, message: '请选择是否收票!', trigger: 'blur'},
          // ],
        },
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.$refs["form"].clearValidate();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.$emit('ok', this.model, this.flag);
          }
        })
      },
    }
  }
</script>
